// let $ = {
//     get:function(url,data,callback){},
//     post:function(url,data,callback){}
// }


// url 路径
// data 请求数据
// callback 回调函数
function ajax(url,data,callback){
    let x = new XMLHttpRequest();
        x.open('post',url);
        x.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        let str = '';
        // {name:12,age:5} => `name=12&age=5`
        for(let item in data){
            // console.log(item); //username,pwd
            // console.log(data[item]); //username.value,pwd.value
            str += item+'='+data[item]+'&';
            // username=123&
        }
        // console.log(str); //`username=123&pwd=321&`;
        str = str.slice(0,-1);
        console.log(str); //`username=111&pwd=222`
        x.send(str);
        x.responseType = 'json';
        x.onreadystatechange = function(){
            if(x.readyState === 4 && x.status === 200){
                callback(x.response)
            }
        }
}